package org.huamoxi.utils;

import lombok.Data;
import org.huamoxi.constant.ResponseStatusConstants;
import org.huamoxi.result.Result;

@Data
public class ResultUtils<T> {

    /**
     * 成功
     */
    public static Result success() {
        return new Result(ResponseStatusConstants.SUCCESS_CODE, ResponseStatusConstants.SUCCESS_MESSAGE);
    }

    public static <T> Result success(T data) {
        return new Result(data);
    }

    public static <T> Result success(String msg, T data) {
        return new Result(msg, data);
    }

    /**
     * 失败
     */
    public static Result fail() {
        return new Result(ResponseStatusConstants.FAIL_CODE, ResponseStatusConstants.FAIL_MESSAGE);
    }

    public static Result fail(String msg) {
        return new Result(ResponseStatusConstants.FAIL_CODE, msg);
    }

    public static Result fail(Integer code, String msg) {
        return new Result(code, msg);
    }

    /**
     * 自定义
     */
    public static <T> Result toResult(int code, String msg, T data) {
        return new Result(code, msg, data);
    }

}
